import { ParallaxLayer } from "./ParallaxLayer";

// ParallaxBackground.ts
const { ccclass, property } = cc._decorator;

@ccclass
export class ParallaxBackground extends cc.Component {
    @property(cc.Node)
    mainCamera: cc.Node = null; // 主摄像机节点

    @property(cc.Vec2)
    scrollOffset: cc.Vec2 = cc.v2(0, 0); // 全局滚动偏移量

    private layers: ParallaxLayer[] = [];

    onLoad() {
        this.layers = this.getComponentsInChildren(ParallaxLayer);
    }

    update(dt: number) {
        const cameraPos = this.mainCamera.position;
        this.layers.forEach(layer => {
            layer.updatePosition(cameraPos, this.scrollOffset);
        });
    }
}